﻿// -----------------------------------------------------------------------
// <copyright file="Status.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Core.Player
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Un4seen.Bass;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public static class Status
    {
        /// <summary>Stores the playback state</summary>
        private static StatusEnum strPlaybackState;

        /// <summary>Stores the current volume value</summary>
        private static int intCurrentVolume;

        /// <summary>
        /// Player status
        /// </summary>
        public enum StatusEnum
        {
            /// <summary>The playback is on</summary>
            Playing,

            /// <summary>The playback is paused</summary>
            Paused,

            /// <summary>The playback is stopped</summary>
            Stopped
        }

        /// <summary>
        /// Gets or sets the volume
        /// </summary>
        public static int Volume
        {
            get
            {
                return intCurrentVolume;
            }
            
            set
            {
                intCurrentVolume = value;
            }
        }

        #region Time properties

        /// <summary>
        /// Gets the total file time in bytes
        /// </summary>
        public static long TotalTimeInBytes
        {
            get
            {
                return Playback.Instance.GetPlayerObject(MediaInfo.CurrentFile).GetTotalTimeInBytes();
            }
        }

        /// <summary>
        /// Gets the total time in seconds
        /// </summary>
        public static double TotalTimeInSeconds
        {
            get
            {
                return Playback.Instance.GetPlayerObject(MediaInfo.CurrentFile).GetTotalTimeInSeconds();
            }
        }

        /// <summary>
        /// Gets the total time in seconds (formatted)
        /// </summary>
        public static string TotalTimeFormated
        {
            get
            {
                if (MediaInfo.CurrentFile == Helper.FileTypeEnum.InternetAudioStream)
                {
                    return "Radio";
                }
                else
                {
                    return string.Format("{0:#0.00}", Utils.FixTimespan(TotalTimeInSeconds, "MMSS"));
                }
            }
        }

        /// <summary>
        /// Gets the current position in seconds
        /// </summary>
        public static double CurrentPositionInSeconds
        {
            get
            {
                //if (MediaInfo.CurrentFile == Helper.FileTypeEnum.InternetAudioStream)
                //{
                //    return 0;
                //}
                //else
                //{
                    return Playback.Instance.GetPlayerObject(MediaInfo.CurrentFile).GetCurrentPositionInSeconds();
                //}
            }
        }

        /// <summary>
        /// Gets the current position in bytes
        /// </summary>
        public static long CurrentPositionInBytes
        {
            get
            {
                return Playback.Instance.GetPlayerObject(MediaInfo.CurrentFile).GetCurrentPositionInBytes();
            }
        }

        /// <summary>
        /// Gets the current position in seconds (formatted)
        /// </summary>
        public static string CurrentPositionFormated
        {
            get
            {
                return string.Format("{0:#0.00}", Utils.FixTimespan(CurrentPositionInSeconds, "MMSS"));
            }
        }

        #endregion

        /// <summary>
        /// Gets or sets the playback status
        /// </summary>
        public static StatusEnum PlaybackStatus
        {
            get
            {
                return strPlaybackState;
            }

            set
            {
                strPlaybackState = value;
            }
        }
    }
}
